package com.imooc.service;

import com.imooc.mapper.BgmMapper;
import com.imooc.pojo.Bgm;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@SuppressWarnings("all")
public class BgmServiceImpl implements BgmService {
    @Autowired
    private BgmMapper bgmMapper;
    @Autowired
    private Sid sid;
    @Override
    public List<Bgm> list() {
        return bgmMapper.selectAll();
    }


    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public Bgm saveBgm(Bgm bgm) {
        //实现全局唯一的id
        String id = sid.nextShort();
        bgm.setId(id);

        bgmMapper.insert(bgm);
        return bgm;

    }
    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public Bgm queryBgm(String bgmid) {
        return bgmMapper.selectByPrimaryKey(bgmid);
    }
}
